package com.timeDeal.servlet;


import com.timeDeal.bean.UserBean;
import com.timeDeal.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Date;

/**
 * Created by Administrator on 2016/7/24.
 */

public class XiugaiGerenXinxiServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String[] yunxu = new String[10];
        for (int i = 1; i < 10; i++) {
            yunxu[i] = request.getParameter("ch" + i);
        }
        UserBean ub = new UserBean();
        ub.setZhanghao(((UserBean) request.getSession().getAttribute("USER")).getZhanghao());
        ub.setGongkai(yunxu);
        ub.setZhenshixingming(request.getParameter("xingming"));
        ub.setShouji(request.getParameter("shouji").trim());
        ub.setXingbie(request.getParameter("xingbie"));
        ub.setShengri(Date.valueOf(request.getParameter("shengri")));
        ub.setTongxundizhi(request.getParameter("juzhudi"));
        ub.setNianling(Integer.valueOf(request.getParameter("nianling")));
        ub.setYouxiang(request.getParameter("youxiang"));
        ub.setGerenxintiao(request.getParameter("gerenxintiao"));
        ub.setShenfenzhenghao(request.getParameter("shenfenzhenghao"));
        UserService gs = new UserService();
        if (gs.tijiaoGerenXinxi(ub)) {
            PrintWriter out = response.getWriter();
            out.print("<script language='javascript'>alert('修改个人信息成功！');</script>");
            request.getRequestDispatcher("/user/zhujiemiangg.jsp").forward(request, response);
        } else {
            PrintWriter out = response.getWriter();
            out.print("<script>alert(\"出错!\");</script>");
            response.setHeader("refresh", "0;url=/TimeDeal/user/zhujiemian.jsp");
        }

    }
}
